home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 61 / Quick PC 61.iso / I386 / IISFTPDR.VB_ / iisftpdr.vbs
Encoding:
Text File  |  2003-02-21  |  32.1 KB  |  889 lines

  1. '
  2. ' Copyright (c) Microsoft Corporation.  All rights reserved.
  3. '
  4. ' VBScript Source File 
  5. '
  6. ' Script Name: IIsFtpDr.vbs
  7. '
  8.  
  9. Option Explicit
  10. On Error Resume Next
  11.  
  12. ' Error codes
  13. Const ERR_OK              = 0
  14. Const ERR_GENERAL_FAILURE = 1
  15.  
  16. '''''''''''''''''''''
  17. ' Messages
  18. Const L_FtpDir_Message           = "Ftp directory %1 has been DELETED"
  19. Const L_InvalidPath_ErrorMessage = "Invalid site path."
  20.  
  21. Const L_VPath_Message        = "Virtual Path"
  22. Const L_Root_Message         = "ROOT"
  23. Const L_MetabasePath_Message = "Metabase Path"
  24. Const L_AliasName_Text       = "Alias"
  25. Const L_Path_Text            = "Physical Root"
  26.  
  27. Const L_Error_ErrorMessage                 = "Error &H%1: %2"
  28. Const L_VDirDel_ErrorMessage               = "Could not delete ftp directory."
  29. Const L_CannotCreateDir_ErrorMessage       = "Could not create root directory."
  30. Const L_DirFormat_ErrorMessage             = "Root directory format unknown. Please use the"
  31. Const L_DirFormat2_ErrorMessage            = "'<drive>:\<path>' format."
  32. Const L_OperationRequired_ErrorMessage     = "Please specify an operation before the arguments."
  33. Const L_NotEnoughParam_ErrorMessage        = "Not enough parameters."
  34. Const L_Query_ErrorMessage                 = "Error occurred while querying WMI provider."
  35. Const L_CmdLib_ErrorMessage                = "Could not create an instance of the CmdLib object."
  36. Const L_ChkCmdLibReg_ErrorMessage          = "Please register the Microsoft.CmdLib component."
  37. Const L_VDirExists1_ErrorMessage           = "The FTP virtual directory %1 does not exist."
  38. Const L_VDirExists2_ErrorMessage           = "The FTP virtual directory %1 already exists."
  39. Const L_VDirDoesntExist_ErrorMessage       = "Virtual directory doesn't exist (%1)"
  40. Const L_OnlyOneOper_ErrorMessage           = "Please specify only one operation at a time."
  41. Const L_ScriptHelper_ErrorMessage          = "Could not create an instance of the IIsScriptHelper object."
  42. Const L_ChkScpHelperReg_ErrorMessage       = "Please register the Microsoft.IIsScriptHelper component."
  43. Const L_VDirsNotFound_ErrorMessage         = "No virtual sub-directories available."
  44. Const L_SiteNotFound_ErrorMessage          = "Could not find ftpsite %1"
  45. Const L_PassWithoutUser_ErrorMessage       = "Please specify /u switch before using /p."
  46. Const L_WMIConnect_ErrorMessage            = "Could not connect to WMI provider."
  47. Const L_MapDrive_ErrorMessage              = "Could not map network drive."
  48. Const L_GetSetting_ErrorMessage            = "Unable to get Setting class from IIS namespace."
  49. Const L_CannotDelRoot_ErrorMessage         = "Cannot delete the ROOT virtual directory. Please specify"
  50. Const L_CannotDelRoot2_ErrorMessage        = "another one."
  51. Const L_KeyIsntVDir_ErrorMessage           = "Specified metabase path is not a virtual directory."
  52. Const L_CannotGetVDir_ErrorMessage         = "Either the path specified does not exist or it is not an"
  53. Const L_CannotGetVDir2_ErrorMessage        = "FTP virtual directory.  Please make sure the path specified"
  54. Const L_CannotGetVDir3_ErrorMessage        = "is valid."
  55. Const L_InvalidAlias_ErrorMessage          = "Alias contains invalid character(s)."
  56. Const L_CannotGetParentVDir_ErrorMessage   = "Error getting parent virtual directory."
  57. Const L_ParentVDirNotPresent_ErrorMessage  = "Parent virtual directory doesn't exist."
  58. Const L_NotEnoughParams_ErrorMessage       = "Not enough parameters."
  59. Const L_InvalidSwitch_ErrorMessage         = "Invalid switch: %1"
  60. Const L_Admin_ErrorMessage                 = "You cannot run this command because you are not an"
  61. Const L_Admin2_ErrorMessage                = "administrator on the server you are trying to configure."
  62.  
  63. '''''''''''''''''''''
  64. ' Help
  65.  
  66. ' General help messages
  67. Const L_SeeHelp_Message          = "Type IIsFtpDr /? for help."
  68. Const L_SeeCreateHelp_Message    = "Type IIsFtpDr /create /? for help."
  69. Const L_SeeDeleteHelp_Message    = "Type IIsFtpDr /delete /? for help."
  70. Const L_SeeQueryHelp_Message     = "Type IIsFtpDr /query /? for help."
  71.  
  72. Const L_Help_HELP_General01_Text  = "Description: Create, delete, or query a ftp directory"
  73. Const L_Help_HELP_General02_Text  = "Syntax: IIsFtpDr [/s <server> [/u <username> [/p <password>]]]"
  74. Const L_Help_HELP_General03_Text  = "        /<operation> [arguments]"
  75. Const L_Help_HELP_General04_Text  = "Parameters:"
  76. Const L_Help_HELP_General06_Text  = "Value                   Description"
  77. Const L_Help_HELP_General07_Text  = "/s <server>             Connect to machine <server>"
  78. Const L_Help_HELP_General07a_Text = "                        [Default: this system]"
  79. Const L_Help_HELP_General08_Text  = "/u <username>           Connect as <domain>\<username> or"
  80. Const L_Help_HELP_General09_Text  = "                        <username> [Default: current user]"
  81. Const L_Help_HELP_General10_Text  = "/p <password>           Password for the <username> user"
  82. Const L_Help_HELP_General11_Text  = "<operation>             /create  Creates a ftp virtual directory"
  83. Const L_Help_HELP_General12_Text  = "                                 on a specified ftp site."
  84. Const L_Help_HELP_General13_Text  = "                        /delete  Deletes a ftp virtual directory"
  85. Const L_Help_HELP_General14_Text  = "                                 from a specified ftp site."
  86. Const L_Help_HELP_General15_Text  = "                        /query   Lists all virtual directories"
  87. Const L_Help_HELP_General16_Text  = "                                 under the specified path."
  88. Const L_Help_HELP_General17_Text  = "For detailed usage:"
  89. Const L_Help_HELP_General18_Text  = "IIsFtpDr /create /?"
  90. Const L_Help_HELP_General19_Text  = "IIsFtpDr /delete /?"
  91. Const L_Help_HELP_General20_Text  = "IIsFtpDr /query /?"
  92.  
  93. ' Common to all status change commands
  94. Const L_Help_HELP_Common03_Text   = "Parameters:"
  95. Const L_Help_HELP_Common09_Text   = "<ftpsite>               Use either the site name or metabase"
  96. Const L_Help_HELP_Common09p1_Text = "                        path to specify the site. (""Default"
  97. Const L_Help_HELP_Common09p2_Text = "                        Ftp Site"" or msftpsvc/1)"
  98. Const L_Help_HELP_Common10_Text   = "<path>                  Virtual path for the new virtual"
  99. Const L_Help_HELP_Common10p1_Text = "                        directory's parent. This virtual"
  100. Const L_Help_HELP_Common10p2_Text = "                        path must already exist."
  101. Const L_Help_HELP_Common11_Text   = "Examples:"
  102.  
  103. ' Delete help messages
  104. Const L_Help_HELP_Delete01_Text   = "Description: Deletes a ftp virtual directory from a"
  105. Const L_Help_HELP_Delete01p1_Text = "             specified ftp site."
  106. Const L_Help_HELP_Delete02_Text   = "Syntax: IIsFtpDr [/s <server> [/u <username> [/p <password>]]]"
  107. Const L_Help_HELP_Delete02p1_Text = "        /delete <ftpsite>[/path]<alias>"
  108. Const L_Help_HELP_Delete11_Text   = "IIsFtpDr /delete ""My Site""/Mydir"
  109. Const L_Help_HELP_Delete12_Text   = "IIsFtpDr /delete msftpsvc/1/ROOT/Users/Public/Mydir"
  110. Const L_Help_HELP_Delete13_Text   = "IIsFtpDr /s Server1 /u Administrator /p p@ssWOrd /delete ""My Site""/Mydir"
  111.  
  112. ' Query help messages
  113. Const L_Help_HELP_Query01_Text   = "Description: Lists all virtual directories under a given"
  114. Const L_Help_HELP_Query01p1_Text = "             path."
  115. Const L_Help_HELP_Query02_Text   = "Syntax: IIsFtpDr [/s <server> [/u <username> [/p <password>]]] /query"
  116. Const L_Help_HELP_Query02p1_Text = "        <ftpsite>[/path]"
  117. Const L_Help_HELP_Query11_Text   = "IIsFtpDr /query ""My Site"""
  118. Const L_Help_HELP_Query12_Text   = "IIsFtpDr /query msftpsvc/1/ROOT"
  119. Const L_Help_HELP_Query13_Text   = "IIsFtpDr /query ""My Site""/Users/Public"
  120. Const L_Help_HELP_Query14_Text   = "IIsFtpDr /s Server1 /u Administrator /p p@ssWOrd /query ""My Site""/Users"
  121.  
  122. ' Create help messages
  123. Const L_Help_HELP_Create01_Text   = "Description: Creates a ftp virtual directory on a specified"
  124. Const L_Help_HELP_Create01p1_Text = "             ftp site."
  125. Const L_Help_HELP_Create02_Text   = "Syntax: IIsFtpDr [/s <server> [/u <username> [/p <password>]]]"
  126. Const L_Help_HELP_Create02p1_Text = "        /create <ftpsite>[/path] <alias> <root>"
  127. Const L_Help_HELP_Create11_Text   = "<alias>                 The name of the virtual directory"
  128. Const L_Help_HELP_Create12_Text   = "<root>                  Physical path of the virtual"
  129. Const L_Help_HELP_Create12p1_Text = "                        directory. If the physical path does"
  130. Const L_Help_HELP_Create12p2_Text = "                        not exist, it will be created."
  131. Const L_Help_HELP_Create15_Text   = "IIsFtpDr /create ""My Site"" Mydir c:\mydir"
  132. Const L_Help_HELP_Create16_Text   = "IIsFtpDr /create msftpsvc/1/ROOT MyDir c:\mydir"
  133. Const L_Help_HELP_Create17_Text   = "IIsFtpDr /create ""My Site""/Users/Public Mydir c:\mydir"
  134. Const L_Help_HELP_Create18_Text   = "IIsFtpDr /s Server1 /u Administrator /p p@assWOrd /create ""My Site"" Mydir"
  135. Const L_Help_HELP_Create19_Text   = "        c:\mydir"
  136.  
  137. ''''''''''''''''''''''''
  138. ' Operation codes
  139. Const OPER_DELETE = 1
  140. Const OPER_CREATE = 2
  141. Const OPER_QUERY  = 3
  142.  
  143. '
  144. ' Main block
  145. '
  146. Dim oScriptHelper, oCmdLib
  147. Dim strServer, strUser, strPassword, strSite
  148. Dim strPath, strVPath, strAlias, strRoot
  149. Dim intOperation, intResult
  150. Dim aArgs, arg
  151. Dim strCmdLineOptions
  152. Dim oError
  153.  
  154. ' Default values
  155. strServer = "."
  156. strUser = ""
  157. strPassword = ""
  158. intOperation = 0
  159. strSite = ""
  160. strPath = ""
  161.  
  162. ' Instantiate the CmdLib for output string formatting
  163. Set oCmdLib = CreateObject("Microsoft.CmdLib")
  164. If Err.Number <> 0 Then
  165.     WScript.Echo L_CmdLib_ErrorMessage
  166.     WScript.Echo L_ChkCmdLibReg_ErrorMessage    
  167.     WScript.Quit(ERR_GENERAL_FAILURE)
  168. End If
  169. Set oCmdLib.ScriptingHost = WScript.Application
  170.  
  171. ' Instantiate script helper object
  172. Set oScriptHelper = CreateObject("Microsoft.IIsScriptHelper")
  173. If Err.Number <> 0 Then
  174.     WScript.Echo L_ScriptHelper_ErrorMessage
  175.     WScript.Echo L_ChkScpHelperReg_ErrorMessage    
  176.     WScript.Quit(ERR_GENERAL_FAILURE)
  177. End If
  178.  
  179. Set oScriptHelper.ScriptHost = WScript
  180.  
  181. ' Check if we are being run with cscript.exe instead of wscript.exe
  182. oScriptHelper.CheckScriptEngine
  183.  
  184. ' Minimum number of parameters must exist
  185. If WScript.Arguments.Count < 1 Then
  186.     WScript.Echo L_NotEnoughParam_ErrorMessage
  187.     WScript.Echo L_SeeHelp_Message
  188.     WScript.Quit(ERR_GENERAL_FAILURE)
  189. End If
  190.  
  191. strCmdLineOptions = "[server:s:1;user:u:1;password:p:1];delete:d:1;create:c:3;query:q:1"
  192. Set oError = oScriptHelper.ParseCmdLineOptions(strCmdLineOptions)
  193.  
  194. If Not oError Is Nothing Then
  195.     If oError.ErrorCode = oScriptHelper.ERROR_NOT_ENOUGH_ARGS Then
  196.         ' Not enough arguments for a specified switch
  197.         WScript.Echo L_NotEnoughParams_ErrorMessage
  198.         Select Case LCase(oError.SwitchName)
  199.             Case "create"
  200.                 WScript.Echo L_SeeCreateHelp_Message
  201.             
  202.             Case "delete"
  203.                 WScript.Echo L_SeeDeleteHelp_Message
  204.  
  205.             Case "query"
  206.                 WScript.Echo L_SeeQueryHelp_Message
  207.  
  208.             Case Else
  209.                    WScript.Echo L_SeeHelp_Message
  210.         End Select
  211.     Else
  212.         ' Invalid switch
  213.         oCmdLib.vbPrintf L_InvalidSwitch_ErrorMessage, Array(oError.SwitchName)
  214.           WScript.Echo L_SeeHelp_Message
  215.     End If
  216.         
  217.         WScript.Quit(ERR_GENERAL_FAILURE)
  218. End If
  219.  
  220. If oScriptHelper.GlobalHelpRequested Then
  221.     DisplayHelpMessage
  222.     WScript.Quit(ERR_OK)
  223. End If
  224.     
  225. For Each arg In oScriptHelper.Switches
  226.     Select Case arg
  227.         Case "server"
  228.             ' Server information
  229.             strServer = oScriptHelper.GetSwitch(arg)
  230.  
  231.         Case "user"
  232.             ' User information
  233.             strUser = oScriptHelper.GetSwitch(arg)
  234.  
  235.         Case "password"
  236.             ' Password information
  237.             strPassword = oScriptHelper.GetSwitch(arg)
  238.         
  239.         Case "create"
  240.             If (intOperation <> 0) Then
  241.                 WScript.Echo L_OnlyOneOper_ErrorMessage
  242.                 WScript.Echo L_SeeHelp_Message
  243.                 WScript.Quit(ERR_GENERAL_FAILURE)
  244.             End If
  245.  
  246.             intOperation = OPER_CREATE
  247.  
  248.                If oScriptHelper.IsHelpRequested(arg) Then
  249.                 DisplayCreateHelpMessage
  250.                 WScript.Quit(ERR_OK)
  251.             End If
  252.  
  253.             aArgs = oScriptHelper.GetSwitch(arg)
  254.  
  255.             strVPath = aArgs(0)
  256.             strAlias = aArgs(1)
  257.             strRoot = aArgs(2)
  258.  
  259.         Case "delete"
  260.             If (intOperation <> 0) Then
  261.                 WScript.Echo L_OnlyOneOper_ErrorMessage
  262.                 WScript.Echo L_SeeHelp_Message
  263.                 WScript.Quit(ERR_GENERAL_FAILURE)
  264.             End If
  265.         
  266.             intOperation = OPER_DELETE
  267.  
  268.             If oScriptHelper.IsHelpRequested(arg) Then
  269.                 DisplayDeleteHelpMessage
  270.                 WScript.Quit(ERR_OK)
  271.             End If
  272.  
  273.             strPath = oScriptHelper.GetSwitch(arg)
  274.  
  275.         Case "query"
  276.             If (intOperation <> 0) Then
  277.                 WScript.Echo L_OnlyOneOper_ErrorMessage
  278.                 WScript.Echo L_SeeHelp_Message
  279.                 WScript.Quit(ERR_GENERAL_FAILURE)
  280.             End If
  281.         
  282.             intOperation = OPER_QUERY
  283.  
  284.             If oScriptHelper.IsHelpRequested(arg) Then
  285.                 DisplayQueryHelpMessage
  286.                 WScript.Quit(ERR_OK)
  287.             End If
  288.  
  289.             strPath = oScriptHelper.GetSwitch(arg)
  290.     End Select
  291. Next
  292.     
  293. ' Check Parameters
  294. If (intOperation = 0) Then
  295.     WScript.Echo L_OperationRequired_ErrorMessage
  296.     WScript.Echo L_SeeHelp_Message
  297.     WScript.Quit(ERR_GENERAL_FAILURE)
  298. End If
  299.  
  300. ' Check if /p is specified but /u isn't. In this case, we should bail out with an error
  301. If oScriptHelper.Switches.Exists("password") And Not oScriptHelper.Switches.Exists("user") Then
  302.     WScript.Echo L_PassWithoutUser_ErrorMessage
  303.     WScript.Quit(ERR_GENERAL_FAILURE)
  304. End If
  305.  
  306. ' Check if /u is specified but /p isn't. In this case, we should ask for a password
  307. If oScriptHelper.Switches.Exists("user") And Not oScriptHelper.Switches.Exists("password") Then
  308.     strPassword = oCmdLib.GetPassword
  309. End If
  310.  
  311. ' Initializes authentication with remote machine
  312. intResult = oScriptHelper.InitAuthentication(strServer, strUser, strPassword)
  313. If intResult <> 0 Then
  314.     WScript.Quit(intResult)
  315. End If
  316.  
  317. ' Choose operation
  318. Select Case intOperation
  319.     Case OPER_CREATE
  320.         intResult = CreateFtpVDir(strVPath, strAlias, strRoot)
  321.         
  322.     Case OPER_DELETE
  323.         intResult = DeleteFtpVDir(strPath)
  324.  
  325.     Case OPER_QUERY
  326.         intResult = QueryFtpVDir(strPath)
  327. End Select
  328.  
  329. ' Return value to command processor
  330. WScript.Quit(intResult)
  331.  
  332. '''''''''''''''''''''''''
  333. ' End Of Main Block
  334. '''''''''''''''''''''
  335.  
  336. '''''''''''''''''''''''''''
  337. ' ParseSitePath
  338. '''''''''''''''''''''''''''
  339. Function ParseSitePath(strSitePath)
  340.     Dim iFirstSlash, iSecondSlash, iIndex
  341.     Dim strSite, strPath
  342.     Dim aPath, aFtpSites
  343.     
  344.     On Error Resume Next
  345.     
  346.     ' Replace any existing back-slashes with forward-slashes
  347.     strSitePath = Replace(strSitePath, "\", "/")
  348.     
  349.     aPath = Split(strSitePath, "/", -1)
  350.  
  351.     ' Fills strPath
  352.     If (UCase(aPath(0)) = "MSFTPSVC") Then
  353.         ' First argument is a metabase path
  354.         If (UBound(aPath) < 1) Then
  355.             WScript.Echo L_InvalidPath_ErrorMessage
  356.             WScript.Quit(ERR_GENERAL_FAILURE)
  357.         End If
  358.         
  359.         ' Second array element must be a number (site ID)
  360.         If Not IsNumeric(aPath(1)) Then
  361.             WScript.Echo L_InvalidPath_ErrorMessage
  362.             WScript.Quit(ERR_GENERAL_FAILURE)
  363.         End If
  364.         
  365.         ' Second element of aPath should be the site number so ...
  366.         strPath = "MSFTPSVC/" & aPath(1)
  367.         
  368.         ' Call FindFtpSite to make sure ftp site exists
  369.         aFtpSites = oScriptHelper.FindSite("Ftp", Array(strPath))
  370.         If IsArray(aFtpSites) Then
  371.             If UBound(aFtpSites) = -1 Then
  372.                 oCmdLib.vbPrintf L_SiteNotFound_ErrorMessage, Array(strPath)
  373.                 ParseSitePath = Empty
  374.                 Exit Function
  375.             End If
  376.         End If
  377.  
  378.         strPath = strPath & "/ROOT"
  379.         strSitePath = strPath
  380.  
  381.         ' Check for ROOT string and grab the rest for strPath
  382.         iIndex = 1
  383.         If (UBound(aPath) > 1) Then
  384.             If (UCase(aPath(2)) = "ROOT") Then
  385.                 iIndex = 2
  386.             End If
  387.         End If
  388.         
  389.     Else
  390.         ' First argument is a site name (server comment property)
  391.         ' Call FindFtpSite to resolve site name to metabase path
  392.         aFtpSites = oScriptHelper.FindSite("Ftp", Array(aPath(0)))
  393.         If IsArray(aFtpSites) Then
  394.             If UBound(aFtpSites) = -1 Then
  395.                 oCmdLib.vbPrintf L_SiteNotFound_ErrorMessage, Array(aPath(0))
  396.                 ParseSitePath = Empty
  397.                 Exit Function
  398.             Else
  399.                 strPath = aFtpSites(0)
  400.             End If
  401.         Else
  402.             ' Got duplicate sites. We should quit.
  403.             ParseSitePath = Empty
  404.             Exit Function
  405.         End If
  406.         
  407.         strPath = strPath & "/ROOT"
  408.         strSitePath = aPath(0) & "/ROOT"
  409.  
  410.         ' Check for ROOT string and grab the rest for strPath
  411.         iIndex = 0
  412.         If (UBound(aPath) > 0) Then
  413.             If (UCase(aPath(1)) = "ROOT") Then
  414.                 iIndex = 1
  415.             End If
  416.         End If
  417.  
  418.     End If
  419.  
  420.     ' Build strPath    
  421.     iIndex = iIndex + 1
  422.     Do While iIndex <= UBound(aPath)
  423.         If (aPath(iIndex) = "") Then
  424.             Exit Do
  425.         End If
  426.         
  427.         strPath = strPath & "/" & aPath(iIndex)
  428.         strSitePath = strSitePath & "/" & aPath(iIndex)
  429.  
  430.         iIndex = iIndex + 1
  431.     Loop
  432.     
  433.     ParseSitePath = strPath
  434. End Function
  435.  
  436.  
  437. '''''''''''''''''''''''''''
  438. ' DisplayHelpMessage
  439. '''''''''''''''''''''''''''
  440. Sub DisplayHelpMessage()
  441.     WScript.Echo L_Help_HELP_General01_Text
  442.     WScript.Echo
  443.     WScript.Echo L_Help_HELP_General02_Text
  444.     WScript.Echo L_Help_HELP_General03_Text
  445.     WScript.Echo 
  446.     WScript.Echo L_Help_HELP_General04_Text
  447.     WScript.Echo 
  448.     WScript.Echo L_Help_HELP_General06_Text
  449.     WScript.Echo L_Help_HELP_General07_Text
  450.     WScript.Echo L_Help_HELP_General07a_Text
  451.     WScript.Echo L_Help_HELP_General08_Text
  452.     WScript.Echo L_Help_HELP_General09_Text
  453.     WScript.Echo L_Help_HELP_General10_Text
  454.     WScript.Echo L_Help_HELP_General11_Text
  455.     WScript.Echo L_Help_HELP_General12_Text
  456.     WScript.Echo L_Help_HELP_General13_Text
  457.     WScript.Echo L_Help_HELP_General14_Text
  458.     WScript.Echo L_Help_HELP_General15_Text
  459.     WScript.Echo L_Help_HELP_General16_Text
  460.     WScript.Echo 
  461.     WScript.Echo L_Help_HELP_General17_Text
  462.     WScript.Echo 
  463.     WScript.Echo L_Help_HELP_General18_Text
  464.     WScript.Echo L_Help_HELP_General19_Text
  465.     WScript.Echo L_Help_HELP_General20_Text
  466. End Sub
  467.  
  468. Sub DisplayDeleteHelpMessage()
  469.     WScript.Echo L_Help_HELP_Delete01_Text
  470.     WScript.Echo L_Help_HELP_Delete01p1_Text
  471.     WScript.Echo 
  472.     WScript.Echo L_Help_HELP_Delete02_Text
  473.     WScript.Echo L_Help_HELP_Delete02p1_Text
  474.     WScript.Echo 
  475.     WScript.Echo L_Help_HELP_Common03_Text
  476.     WScript.Echo 
  477.     WScript.Echo L_Help_HELP_General06_Text
  478.     WScript.Echo L_Help_HELP_General07_Text
  479.     WScript.Echo L_Help_HELP_General07a_Text
  480.     WScript.Echo L_Help_HELP_General08_Text
  481.     WScript.Echo L_Help_HELP_General09_Text
  482.     WScript.Echo L_Help_HELP_General10_Text
  483.     WScript.Echo L_Help_HELP_Common09_Text
  484.     WScript.Echo L_Help_HELP_Common09p1_Text
  485.     WScript.Echo L_Help_HELP_Common09p2_Text
  486.     WScript.Echo L_Help_HELP_Common10_Text
  487.     WScript.Echo L_Help_HELP_Common10p1_Text
  488.     WScript.Echo L_Help_HELP_Common10p2_Text
  489.     WScript.Echo 
  490.     WScript.Echo L_Help_HELP_Common11_Text
  491.     WScript.Echo 
  492.     WScript.Echo L_Help_HELP_Delete11_Text
  493.     WScript.Echo L_Help_HELP_Delete12_Text
  494.     WScript.Echo L_Help_HELP_Delete13_Text
  495. End Sub
  496.  
  497. Sub DisplayCreateHelpMessage()
  498.     WScript.Echo L_Help_HELP_Create01_Text
  499.     WScript.Echo L_Help_HELP_Create01p1_Text
  500.     WScript.Echo
  501.     WScript.Echo L_Help_HELP_Create02_Text
  502.     WScript.Echo L_Help_HELP_Create02p1_Text
  503.     WScript.Echo
  504.     WScript.Echo L_Help_HELP_Common03_Text
  505.     WScript.Echo
  506.     WScript.Echo L_Help_HELP_General06_Text
  507.     WScript.Echo L_Help_HELP_General07_Text
  508.     WScript.Echo L_Help_HELP_General07a_Text
  509.     WScript.Echo L_Help_HELP_General08_Text
  510.     WScript.Echo L_Help_HELP_General09_Text
  511.     WScript.Echo L_Help_HELP_General10_Text
  512.     WScript.Echo L_Help_HELP_Common09_Text
  513.     WScript.Echo L_Help_HELP_Common09p1_Text
  514.     WScript.Echo L_Help_HELP_Common09p2_Text
  515.     WScript.Echo L_Help_HELP_Common10_Text
  516.     WScript.Echo L_Help_HELP_Common10p1_Text
  517.     WScript.Echo L_Help_HELP_Common10p2_Text
  518.     WScript.Echo L_Help_HELP_Create11_Text
  519.     WScript.Echo L_Help_HELP_Create12_Text
  520.     WScript.Echo L_Help_HELP_Create12p1_Text
  521.     WScript.Echo L_Help_HELP_Create12p2_Text
  522.     WScript.Echo
  523.     WScript.Echo L_Help_HELP_Common11_Text
  524.     WScript.Echo
  525.     WScript.Echo L_Help_HELP_Create15_Text
  526.     WScript.Echo L_Help_HELP_Create16_Text
  527.     WScript.Echo L_Help_HELP_Create17_Text
  528.     WScript.Echo L_Help_HELP_Create18_Text
  529.     WScript.Echo L_Help_HELP_Create19_Text
  530. End Sub
  531.  
  532. Sub DisplayQueryHelpMessage()
  533.     WScript.Echo L_Help_HELP_Query01_Text
  534.     WScript.Echo L_Help_HELP_Query01p1_Text
  535.     WScript.Echo
  536.     WScript.Echo L_Help_HELP_Query02_Text
  537.     WScript.Echo L_Help_HELP_Query02p1_Text
  538.     WScript.Echo
  539.     WScript.Echo L_Help_HELP_Common03_Text
  540.     WScript.Echo
  541.     WScript.Echo L_Help_HELP_General06_Text
  542.     WScript.Echo L_Help_HELP_General07_Text
  543.     WScript.Echo L_Help_HELP_General07a_Text
  544.     WScript.Echo L_Help_HELP_General08_Text
  545.     WScript.Echo L_Help_HELP_General09_Text
  546.     WScript.Echo L_Help_HELP_General10_Text
  547.     WScript.Echo L_Help_HELP_Common09_Text
  548.     WScript.Echo L_Help_HELP_Common09p1_Text
  549.     WScript.Echo L_Help_HELP_Common09p2_Text
  550.     WScript.Echo L_Help_HELP_Common10_Text
  551.     WScript.Echo L_Help_HELP_Common10p1_Text
  552.     WScript.Echo L_Help_HELP_Common10p2_Text
  553.     WScript.Echo
  554.     WScript.Echo L_Help_HELP_Common11_Text
  555.     WScript.Echo
  556.     WScript.Echo L_Help_HELP_Query11_Text
  557.     WScript.Echo L_Help_HELP_Query12_Text
  558.     WScript.Echo L_Help_HELP_Query13_Text
  559.     WScript.Echo L_Help_HELP_Query14_Text
  560. End Sub
  561.  
  562. '''''''''''''''''''''''''''
  563. ' DeleteFtpVDir
  564. '''''''''''''''''''''''''''
  565. Function DeleteFtpVDir(strVPath)
  566.     Dim strPath, ServiceObj
  567.     Dim rootVDirObj, providerObj
  568.     
  569.     On Error Resume Next
  570.     
  571.     oScriptHelper.WMIConnect
  572.     If Err.Number Then
  573.         WScript.Echo L_WMIConnect_ErrorMessage
  574.         oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  575.         ChangeFtpSiteStatus = Err.Number
  576.         Exit Function
  577.     End If
  578.  
  579.     Set providerObj = oScriptHelper.ProviderObj
  580.  
  581.     ' Quick check to see if we have permission
  582.     Set ServiceObj = providerObj.Get("IIsFtpService='MSFTPSVC'")
  583.     If Err.Number Then
  584.         Select Case Err.Number
  585.             Case &H80070005
  586.                 WScript.Echo L_Admin_ErrorMessage
  587.                 WScript.Echo L_Admin2_ErrorMessage
  588.  
  589.             Case Else
  590.                 WScript.Echo Err.Description
  591.         End Select
  592.         
  593.         DeleteFtpVDir = Err.Number
  594.         Exit Function
  595.     End If
  596.  
  597.     strPath = ParseSitePath(strVPath)
  598.     If IsEmpty(strPath) Then
  599.         ' Got problems parsing the path
  600.         WScript.Echo L_SeeDeleteHelp_Message
  601.         DeleteFtpVDir = ERR_GENERAL_FAILURE
  602.         Exit Function
  603.     End If
  604.     
  605.     ' Don't delete ROOT Vdir
  606.     If UCase(Right(strPath, 5)) = "/ROOT" Then
  607.         WScript.Echo L_CannotDelRoot_ErrorMessage
  608.         WScript.Echo L_CannotDelRoot2_ErrorMessage
  609.         DeleteFtpVDir = ERR_GENERAL_FAILURE
  610.         Exit Function
  611.     End If
  612.     
  613.     ' Check vdir existance
  614.     Set rootVDirObj = providerObj.Get("IIsFtpVirtualDir='" & strPath & "'")
  615.     If Err.Number Then
  616.         Select Case Err.Number
  617.             Case &H80041002
  618.                 oCmdLib.vbPrintf L_VDirDoesntExist_ErrorMessage, Array(strVPath)
  619.         
  620.             Case &H8004103A
  621.                 WScript.Echo L_KeyIsntVDir_ErrorMessage
  622.                 
  623.             Case Else
  624.                 oCmdLib.vbPrintf L_VDirExists1_ErrorMessage, Array(strVPath)
  625.                 WScript.Echo L_CannotGetVDir_ErrorMessage
  626.                 WScript.Echo L_CannotGetVDir2_ErrorMessage
  627.                 WScript.Echo L_CannotGetVDir3_ErrorMessage
  628.         End Select
  629.         
  630.         DeleteFtpVDir = Err.Number
  631.         Exit Function
  632.     End If
  633.     
  634.     rootVDirObj.Delete_()
  635.     If Err.Number Then
  636.         WScript.Echo L_VDirDel_ErrorMessage
  637.         oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  638.         DeleteFtpVDir = Err.Number
  639.         Exit Function
  640.     End If
  641.  
  642.        oCmdLib.vbPrintf L_FtpDir_Message, Array(strVPath)
  643.     
  644.     DeleteFtpVDir = ERR_OK
  645. End Function
  646.  
  647.  
  648. '''''''''''''''''''''''''''
  649. ' CreateFtpVDir
  650. '''''''''''''''''''''''''''
  651. Function CreateFtpVDir(strVPath, strAlias, strRoot)
  652.     Dim strPath, strStatus, strNewVdir, strRootVDir
  653.     Dim vdirClassObj, serverObj, vdirObj, providerObj
  654.     Dim intResult, ServiceObj
  655.  
  656.     On Error Resume Next
  657.     
  658.     ' Parse Alias for correctness
  659.     If InStr(strAlias, "/") <> 0 Or InStr(strAlias, "\") <> 0 Then
  660.         WScript.Echo L_InvalidAlias_ErrorMessage
  661.         WScript.Echo L_SeeCreateHelp_Message
  662.         CreateWebVDir = ERR_GENERAL_FAILURE
  663.         Exit Function
  664.     End If
  665.  
  666.     oScriptHelper.WMIConnect
  667.     If Err.Number Then
  668.         WScript.Echo L_WMIConnect_ErrorMessage
  669.         oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  670.         CreateFtpVDir = Err.Number
  671.         Exit Function
  672.     End If
  673.  
  674.     Set providerObj = oScriptHelper.ProviderObj
  675.     
  676.     ' Quick check to see if we have permission
  677.     Set ServiceObj = providerObj.Get("IIsFtpService='MSFTPSVC'")
  678.     If Err.Number Then
  679.         Select Case Err.Number
  680.             Case &H80070005
  681.                 WScript.Echo L_Admin_ErrorMessage
  682.                 WScript.Echo L_Admin2_ErrorMessage
  683.  
  684.             Case Else
  685.                 WScript.Echo Err.Description
  686.         End Select
  687.         
  688.         CreateFtpVDir = Err.Number
  689.         Exit Function
  690.     End If
  691.  
  692.     ' Extract options from array to the correspondent variables
  693.     strPath = ParseSitePath(strVPath)
  694.     If IsEmpty(strPath) Then
  695.         ' Got problems parsing the path
  696.         WScript.Echo L_SeeCreateHelp_Message
  697.         CreateFtpVDir = ERR_GENERAL_FAILURE
  698.         Exit Function
  699.     End If
  700.  
  701.     ' Build new vdir name
  702.     strNewVdir = strPath & "/" & strAlias
  703.     
  704.     ' Check if vdir already exists
  705.     Set vdirObj = providerObj.Get("IIsFtpVirtualDirSetting='" & strNewVdir & "'")
  706.     If Err.Number = 0 Then
  707.         oCmdLib.vbPrintf L_VDirExists2_ErrorMessage, Array(strNewVdir)
  708.         CreateFtpVDir = ERR_GENERAL_FAILURE
  709.         Exit Function
  710.     End If
  711.     Err.Clear
  712.     
  713.     ' Check if parent vdir exists
  714.     ' We need to do this because FTP doesn't have the concept similar to a WebDirectory
  715.     Set vdirObj = providerObj.Get("IIsFtpVirtualDirSetting='" & strPath & "'")
  716.     If Err.Number Then
  717.         Select Case Err.Number
  718.             Case &H80041002
  719.                 WScript.Echo L_ParentVDirNotPresent_ErrorMessage
  720.                 
  721.             Case Else
  722.                 WScript.Echo L_CannotGetParentVDir_ErrorMessage
  723.                 oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  724.         End Select
  725.         
  726.         CreateFtpVDir = Err.Number
  727.         Exit Function
  728.     End If
  729.  
  730.     ' Create physical directory
  731.     oScriptHelper.CreateFSDir strRoot
  732.     If Err.Number Then
  733.         Select Case Err.Number
  734.             Case &H8007000C
  735.                 WScript.Echo L_DirFormat_ErrorMessage
  736.                 WScript.Echo L_DirFormat2_ErrorMessage
  737.                 WScript.Echo L_SeeCreateHelp_Message
  738.             
  739.             Case &H8007000F
  740.                 WScript.Echo L_MapDrive_ErrorMessage
  741.     
  742.             Case Else
  743.                 WScript.Echo L_CannotCreateDir_ErrorMessage
  744.                 oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  745.         End Select
  746.  
  747.         CreateFtpVDir = Err.Number
  748.         Exit Function
  749.     End If
  750.  
  751.     ' Remove trailing slash (if present)
  752.     If (Right(strRoot, 1) = "\") Then
  753.         strRoot = Left(strRoot, Len(strRoot) - 1)
  754.     End If
  755.  
  756.     ' Create new ftp virtual directory
  757.     Set vdirClassObj = providerObj.Get("IIsFtpVirtualDirSetting")
  758.     Set vdirObj = vdirClassObj.SpawnInstance_()
  759.     vdirObj.Name = strNewVdir
  760.     vdirObj.Path = strRoot
  761.  
  762.     ' Set ftp virtual directory properties
  763.     vdirObj.AccessFlags = 1 ' read access
  764.     vdirObj.Put_()
  765.  
  766.     ' Remove trailing slash (if present)
  767.     If (Right(strVPath, 1) = "/") Then
  768.         strVPath = Left(strVPath, Len(strVPath) - 1)
  769.     End If
  770.     
  771.     If (strServer = ".") Then 
  772.         strServer = oScriptHelper.GetEnvironmentVar("%COMPUTERNAME%")
  773.     End If
  774.  
  775.     ' Post summary
  776.     WScript.Echo L_Server_Message & Space(14 - Len(L_Server_Message)) & "= " & UCase(strServer)
  777.     WScript.Echo L_VPath_Message & Space(14 - Len(L_VPath_Message)) & "= " & strVPath & "/" & strAlias
  778.     WScript.Echo L_Root_Message & Space(14 - Len(L_Root_Message)) & "= " & strRoot
  779.     WScript.Echo L_MetabasePath_Message & Space(14 - Len(L_MetabasePath_Message)) & "= " & strNewVdir
  780.     
  781.     CreateFtpVDir = intResult
  782. End Function
  783.  
  784.  
  785. '''''''''''''''''''''''''''
  786. ' Helper Functions
  787. '''''''''''''''''''''''''''
  788.  
  789. '''''''''''''''''''''''''''
  790. ' QueryFtpVDir
  791. '''''''''''''''''''''''''''
  792. Function QueryFtpVDir(strVDir)
  793.     Dim Servers, Server, strQuery
  794.     Dim bFirstIteration, ServiceObj
  795.     Dim vdirObj, providerObj
  796.     Dim strServer, strPath, strVDirName
  797.     Dim firstLen
  798.  
  799.     On Error Resume Next
  800.  
  801.     oScriptHelper.WMIConnect
  802.     If Err.Number Then
  803.         WScript.Echo L_WMIConnect_ErrorMessage
  804.         oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  805.         QueryFtpVDir = Err.Number
  806.         Exit Function
  807.     End If
  808.  
  809.     Set providerObj = oScriptHelper.ProviderObj
  810.  
  811.     ' Quick check to see if we have permission
  812.     Set ServiceObj = providerObj.Get("IIsFtpService='MSFTPSVC'")
  813.     If Err.Number Then
  814.         Select Case Err.Number
  815.             Case &H80070005
  816.                 WScript.Echo L_Admin_ErrorMessage
  817.                 WScript.Echo L_Admin2_ErrorMessage
  818.  
  819.             Case Else
  820.                 WScript.Echo Err.Description
  821.         End Select
  822.         
  823.         QueryFtpVDir = Err.Number
  824.         Exit Function
  825.     End If
  826.  
  827.     strPath = ParseSitePath(strVDir)
  828.     If IsEmpty(strPath) Then
  829.         ' Got problems parsing the path
  830.         WScript.Echo L_SeeQueryHelp_Message
  831.         QueryFtpVDir = ERR_GENERAL_FAILURE
  832.         Exit Function
  833.     End If
  834.  
  835.     ' Semi-sync query. (flags = ForwardOnly Or ReturnImediately = &H30)
  836.     strQuery = "ASSOCIATORS OF {IIsFtpVirtualDir=""" & strPath & """} WHERE ResultClass = IIsFtpVirtualDir " & _
  837.         "ResultRole = PartComponent"
  838.     Set Servers = providerObj.ExecQuery(strQuery, , &H30)
  839.     If (Err.Number <> 0) Then
  840.         WScript.Echo L_Query_ErrorMessage
  841.         oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  842.         QueryFtpVDir = Err.Number
  843.         Exit Function
  844.     End If
  845.  
  846.     bFirstIteration = True
  847.     For Each Server in Servers
  848.  
  849.         If Server.Name = "" Then
  850.             WScript.Echo L_CannotGetVDir_ErrorMessage
  851.             WScript.Echo L_CannotGetVDir2_ErrorMessage
  852.             WScript.Echo L_CannotGetVDir3_ErrorMessage
  853.             Exit Function
  854.         End If
  855.  
  856.         If bFirstIteration Then
  857.             WScript.Echo L_AliasName_Text & Space(25 - Len(L_AliasName_Text)) & L_Path_Text
  858.             WScript.Echo "=============================================================================="
  859.         End If
  860.         
  861.         Set vdirObj = providerObj.get("IIsFtpVirtualDirSetting=""" & Server.Name & """")
  862.         If (Err.Number <> 0) Then
  863.             WScript.Echo L_GetSetting_ErrorMessage
  864.             oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  865.             QueryFtpVDir = Err.Number
  866.             Exit Function
  867.         End If
  868.         
  869.         ' If this is the first binding list, print server comment and server name
  870.         strVDirName = Replace(vdirObj.Name, strPath, "") ', , , vbTextCompare)
  871.  
  872.         firstLen = 25 - Len(strVDirName)
  873.  
  874.         If (firstLen < 1) Then
  875.             firstLen = 1
  876.         End If
  877.  
  878.         WScript.Echo strVDirName & Space(firstLen) & vdirObj.Path
  879.         
  880.         bFirstIteration = False
  881.     Next
  882.  
  883.     If bFirstIteration Then
  884.         WScript.Echo L_VDirsNotFound_ErrorMessage
  885.     End If
  886.  
  887.     QueryFtpVDir = ERR_OK
  888. End Function
  889.